package com.ll.app.controller;

import com.ll.app.api.req.*;
import com.ll.base.dto.ApiResultDTO;
import com.ll.base.dto.IdDTO;
import com.ll.base.dto.TenantAndIdDTO;
import com.ll.base.dto.TenantIdDTO;
import com.ll.dal.po.PkPO;
import com.ll.domain.pk.biz.PkDomainService;
import com.ll.domain.pk.event.producer.UpdateStatusPkEvent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/pk")
@RequiredArgsConstructor
@Api(tags = "PK相关API")
public class PkController {

    private final PkDomainService pkDomainService;

    @ResponseBody
    @ApiOperation(value = "查询我的pk的记录")
    @RequestMapping(value = "/getMyPk", method = RequestMethod.POST)
    public ApiResultDTO getMyPk(@RequestBody @Validated TenantAndIdDTO dto) {
        return ApiResultDTO.success(pkDomainService.getMyPk(dto));
    }



    @ResponseBody
    @ApiOperation(value = "查询pkList")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResultDTO list(@RequestBody @Validated ListPkReqDTO dto) {
        return ApiResultDTO.success(pkDomainService.list(dto));
    }

    @ResponseBody
    @ApiOperation(value = "发起pk")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiResultDTO add(@RequestBody @Validated AddPkReqDTO addDTO) {
        pkDomainService.add(addDTO);
        return ApiResultDTO.success();
    }

    @ResponseBody
    @ApiOperation(value = "修改状态")
    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    public ApiResultDTO updateStatus(@RequestBody @Validated UpdateStatusPkReqDTO reqDTO) {
        pkDomainService.updateStatus(reqDTO);
        return ApiResultDTO.success();
    }

    @ResponseBody
    @ApiOperation(value = "修改结果")
    @RequestMapping(value = "/updateResult", method = RequestMethod.POST)
    public ApiResultDTO updateResult(@RequestBody @Validated UpdateResultPkReqDTO reqDTO) {
        pkDomainService.updateResult(reqDTO);
        return ApiResultDTO.success();
    }

}


